home *** CD-ROM | disk | FTP | other *** search
- package com.extensibility.saf.impl;
-
- import com.extensibility.saf.AdjunctException;
- import com.extensibility.saf.Association;
- import com.extensibility.saf.MetaSchema;
- import com.extensibility.saf.SchemaAdjunct;
- import java.io.File;
- import java.io.IOException;
- import java.util.Enumeration;
- import java.util.Hashtable;
- import java.util.Properties;
- import javax.xml.parsers.DocumentBuilder;
- import javax.xml.parsers.DocumentBuilderFactory;
- import javax.xml.parsers.ParserConfigurationException;
- import org.w3c.dom.Attr;
- import org.w3c.dom.Document;
- import org.w3c.dom.Element;
- import org.w3c.dom.Node;
- import org.w3c.dom.NodeList;
- import org.xml.sax.EntityResolver;
- import org.xml.sax.SAXException;
-
- public class SimpleSchemaAdjunct implements SchemaAdjunct, Tags {
- protected MetaSchema metaSchema;
- protected Hashtable associationMap;
- protected String target;
-
- public SimpleSchemaAdjunct(Document var1, MetaSchema var2) {
- this.init(var1, var2);
- }
-
- public SimpleSchemaAdjunct(String var1, MetaSchema var2) {
- this.associationMap = new Hashtable();
- this.target = var1;
- this.metaSchema = var2;
- }
-
- public SimpleSchemaAdjunct(File var1, EntityResolver var2, MetaSchema var3) throws SAXException, IOException {
- try {
- DocumentBuilderFactory var4 = DocumentBuilderFactory.newInstance();
- var4.setValidating(false);
- DocumentBuilder var5 = var4.newDocumentBuilder();
- if (var2 != null) {
- var5.setEntityResolver(var2);
- }
-
- Document var6 = var5.parse(var1);
- this.init(var6, var3);
- } catch (ParserConfigurationException var7) {
- ((Throwable)var7).printStackTrace();
- System.exit(1);
- }
-
- }
-
- private void init(Document var1, MetaSchema var2) {
- this.metaSchema = var2;
- this.associationMap = new Hashtable();
- this.target = var1.getDocumentElement().getAttribute("target");
- this.gatherAssociations(var1, "document", 0);
- this.gatherAssociations(var1, "element", 1);
- this.gatherAssociations(var1, "attribute", 2);
- }
-
- public String getTarget() {
- return this.target;
- }
-
- public MetaSchema getMetaSchema() {
- return this.metaSchema;
- }
-
- public Association[] getAssociations() {
- Association[] var1 = new Association[this.associationMap.size()];
- Enumeration var2 = this.associationMap.keys();
-
- for(int var3 = 0; var3 < this.associationMap.size(); ++var3) {
- var1[var3] = (Association)this.associationMap.get(var2.nextElement());
- }
-
- return var1;
- }
-
- public Association[] getAssociations(String var1) {
- Association var2 = (Association)this.associationMap.get(var1);
- if (var2 == null) {
- return new Association[0];
- } else {
- Association[] var3 = new Association[]{var2};
- return var3;
- }
- }
-
- public Association[] getAssociations(Element var1) {
- return this.getAssociations(var1.getNodeName());
- }
-
- public Association[] getAssociations(Element var1, Attr var2) {
- return this.getAssociations(String.valueOf(String.valueOf(var1.getNodeName()).concat(String.valueOf("/@"))).concat(String.valueOf(var2.getNodeName())));
- }
-
- public String getProperty(String var1, String var2) {
- return this.getProperty(this.getAssociations(var1), var2);
- }
-
- public String getProperty(Element var1, String var2) {
- return this.getProperty(this.getAssociations(var1), var2);
- }
-
- public String getProperty(Element var1, Attr var2, String var3) {
- return this.getProperty(this.getAssociations(var1, var2), var3);
- }
-
- protected String getProperty(Association[] var1, String var2) {
- return var1.length == 0 ? null : var1[0].getProperty(var2);
- }
-
- protected void gatherAssociations(Document var1, String var2, int var3) {
- NodeList var4 = var1.getElementsByTagName(var2);
-
- for(int var5 = 0; var5 < var4.getLength(); ++var5) {
- Node var6 = var4.item(var5);
- String var7;
- if (var3 == 0) {
- var7 = "/";
- } else {
- var7 = ((Element)var6).getAttribute("which");
- }
-
- Properties var8 = this.gatherProperties(var6);
- SimpleAssociation var9 = new SimpleAssociation(this, var3, var7, var8);
- this.associationMap.put(var7, var9);
- }
-
- }
-
- protected Properties gatherProperties(Node var1) {
- Properties var2 = new Properties();
-
- for(Node var3 = var1.getFirstChild(); var3 != null; var3 = var3.getNextSibling()) {
- if (var3 instanceof Element) {
- ((Hashtable)var2).put(var3.getNodeName(), this.gatherText(var3));
- }
- }
-
- return var2;
- }
-
- protected String gatherText(Node var1) {
- StringBuffer var2 = new StringBuffer();
-
- for(Node var3 = var1.getFirstChild(); var3 != null; var3 = var3.getNextSibling()) {
- var2.append(var3.getNodeValue());
- }
-
- return var2.toString();
- }
-
- public Association createAssociation(int var1, String var2) {
- if (var1 == 0) {
- var2 = "/";
- }
-
- Properties var3 = new Properties();
- SimpleAssociation var4 = new SimpleAssociation(this, var1, var2, var3);
- if (this.associationMap.get(var2) != null) {
- throw new AdjunctException("can't add duplicate selector");
- } else {
- this.associationMap.put(var2, var4);
- return var4;
- }
- }
-
- public void removeAssociation(Association var1) {
- this.associationMap.remove(var1.getSelector());
- }
-
- public Document getDocument() {
- return null;
- }
- }
-